/**
    入驻小区
**/
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            chainSupplierInfo: {
                conditions: {
                    products: [],
                    prodName: '',
                    csId: '',
                    catalogId: '',
                    productId: '',
                    shopId: vc.getCurrentCommunity().shopId
                },
                products: [],
                sort: ''
            }
        },
        _initMethod: function() {

        },
        _initEvent: function() {

            vc.on('pagination', 'page_event', function(_currentPage) {
                DEFAULT_PAGE = _currentPage;
                $that._listProducts(_currentPage, DEFAULT_ROWS);
            });

            vc.on('chainSupplier', 'switchSupplier', function(_param) {
                $that.chainSupplierInfo.conditions.csId = _param.csId;
                $that.chainSupplierInfo.conditions.catalogId = '';
                $that._listProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('chainSupplier', 'switchCatalog', function(_param) {
                $that.chainSupplierInfo.conditions.csId = _param.csId;

                console.log(_param.csId);
                $that.chainSupplierInfo.conditions.catalogId = _param.catalogId;
                $that._listProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            });
        },
        methods: {
            //查询
            _queryProductMethod: function() {
                $that._listProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _listProducts: function(_page, _rows) {
                $that.chainSupplierInfo.conditions.page = _page;
                $that.chainSupplierInfo.conditions.row = _rows;
                let param = {
                    params: $that.chainSupplierInfo.conditions
                };
                param.params.prodName = param.params.prodName.trim();
                //发送get请求
                vc.http.apiGet('/chainProduct.listChainProduct',
                    param,
                    function(json, res) {
                        let _productManageInfo = JSON.parse(json);
                        $that.chainSupplierInfo.total = _productManageInfo.total;
                        $that.chainSupplierInfo.records = _productManageInfo.records;
                        $that.chainSupplierInfo.products = _productManageInfo.data;
                        $that.chainSupplierInfo.sort = $that.chainSupplierInfo.products.length;
                        vc.emit('pagination', 'init', {
                            total: $that.chainSupplierInfo.records,
                            dataCount: $that.chainSupplierInfo.total,
                            currentPage: _page
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddProductModel: function(_product) {
                vc.emit('addChainSupplierProduct', 'openAddChainSupplierProductModal', _product);
            },
        }
    });
})(window.vc);